package com.simple.trade.controller.india;

import com.simple.common.entity.ResData;
import com.simple.common.entity.controller.BaseController;
import com.simple.common.entity.req.india.req.IndiaWithdrawalQueryReq;
import com.simple.common.entity.req.india.req.IndiaWithdrawalReq;
import com.simple.common.entity.req.india.res.IndiaWithdrawalQueryRes;
import com.simple.common.entity.req.india.res.IndiaWithdrawalRes;
import com.simple.trade.holder.PayContext;
import com.simple.trade.service.india.WithdrawalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import static com.simple.common.entity.constant.Payment.INDIA_WITHDRAWAL_CODE;

/**
 * @author yasud
 * @date 2021年11月03日 22:09
 * @description
 */
@RestController
public class TransferController extends BaseController {

    @Autowired
    WithdrawalService withdrawalService;

    /**
     * 印度代付申请
     *
     * @param req
     * @return
     */
    @PostMapping("/v3/transfer")
    public ResData<IndiaWithdrawalRes> withdrawal(@RequestBody @Validated IndiaWithdrawalReq req) {
        PayContext.current().iam(req.getAppId(), INDIA_WITHDRAWAL_CODE);
        req.check();
        return withdrawalService.withdrawal(req);
    }

    /**
     * 印度代付查询
     * @param req
     * @return
     */
    @PostMapping("/transfer/query")
    public ResData<IndiaWithdrawalQueryRes> withdrawalQuery(@RequestBody @Validated IndiaWithdrawalQueryReq req) {
        req.check();
        ResData<IndiaWithdrawalQueryRes> queryTradeResResData = withdrawalService.withdrawalQuery(req);
        return queryTradeResResData;
    }
}
